package com.touchportfolio.model.utils
{
	import com.greensock.TweenLite;
	import com.quasimondo.geom.ColorMatrix;
	
	import flash.display.Sprite;
	import flash.filters.ColorMatrixFilter;

	public class EffectsUtilities extends Sprite
	{
		private static var _amount:Number = 0;
		private static var _cm:ColorMatrix; 
		
		public function EffectsUtilities()
		{
		}
		
		public static function setSpriteToColor(sprite:Sprite, tintValue:Number, amount:Number):void
		{
			_cm = new ColorMatrix();
			_cm.colorize(tintValue,amount);
			sprite.filters = [ new flash.filters.ColorMatrixFilter( _cm.matrix ) ];
		}
		
		public static function setSpriteToColorTween(sprite:Sprite, tintValue:Number, transformTime:Number,easeIn:Boolean,amount:int):void
		{
			_amount = amount;
			TweenLite.to(sprite, transformTime, {onUpdate:updateSprite,onUpdateParams:[sprite,tintValue,transformTime,easeIn]});
		}
		
		private static function updateSprite(sprite:Sprite, tintValue:Number, transformTime:Number,easeIn:Boolean):void{
			if(easeIn == true){
				if(_amount < 1){
					_amount += 1 / (25*transformTime);
				}
			}else{
				if(_amount > 0){
					_amount -= 1 / (25*transformTime);
				}
			}
			setSpriteToColor(sprite,tintValue,_amount);
		}
		
		
	}
}